#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

typedef unsigned long LONG;
unsigned short Iter = 0;

LONG Reverse(LONG N, LONG M) {
	if(N == 0) return M;
	M = ((M << 3) + (M << 1));
	M += N%10;
	return Reverse(N/10, M); 
}


LONG Palindrome(LONG& X) {
	X += Reverse(X, 0);
	Iter++;
	if(X == Reverse(X, 0)) return X;
	Palindrome(X);
}

/* main
 *  * */
int main() {
	std::ios_base::sync_with_stdio (true);
	LONG X;
	short testcases;
	cin >> testcases;
	do {
		cin >> X;
		Iter = 0;
		cout << Iter << " " << Palindrome(X) << endl;

	} while(cin.eof() == false && --testcases > 0);
	return 0;
}
